import java.util.Scanner;
import java.util.Vector;


public class Projetoooo {
	
	Scanner input;
	
	public Projetoooo() {
		
		input = new Scanner(System.in);
		
		GLC g = new GLC();
		
		String l1="A,B", l2="0", l3="A->00,B->0|A", l4="B";
		
		g.variaveis = l1.split(",");
		g.alfabeto = l2.split(",");
		g.inicial = l4;
		
		for(String regra : l3.split(",")){
			
			String var = regra.split("->")[0];
			String[] r = regra.split("->")[1].replace('|', ',').split(",");
			
			Vector<String> rs = new Vector<String>();
			
			for(String str : r){
				rs.add(str);
			}
			
			g.regras.put(var, rs);
		}
		
		String str = input.nextLine();
		
		while(!str.equals("#")){
			
			boolean resposta = g.testarCadeia(str);
			
			if(resposta){
				System.out.println("Aceita");
			} else {
				System.out.println("Rejeita");
			}
			
			str = input.nextLine();
		}
	}
	
	public static void main(String[] args) {
		new Projetoooo();
	}
}
